package com.mob.commons.iosbridge;

import android.content.Context;
import android.util.Base64;
import com.mob.commons.j;
import com.mob.tools.MobLog;
import com.mob.tools.log.NLog;
import com.mob.tools.network.KVPair;
import com.mob.tools.network.NetworkHelper;
import com.mob.tools.network.NetworkHelper.NetworkTimeOut;
import com.mob.tools.utils.Data;
import com.mob.tools.utils.DeviceHelper;
import com.mob.tools.utils.Hashon;
import com.mob.tools.utils.R;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.CRC32;

public class UDPServer
{
  private static UDPServer a;
  private Context b;
  private boolean c;

  private UDPServer(Context paramContext)
  {
    this.b = paramContext.getApplicationContext();
  }

  private String a(String paramString)
  {
    Process localProcess = Runtime.getRuntime().exec("cat /proc/net/arp");
    BufferedReader localBufferedReader = new BufferedReader(new InputStreamReader(localProcess.getInputStream()));
    String str1 = localBufferedReader.readLine();
    String str2 = null;
    while (str1 != null)
    {
      if ((str1.startsWith(paramString)) && (!str1.contains("00:00:00:00:00:00")))
      {
        Matcher localMatcher = Pattern.compile("\\w{2}:\\w{2}:\\w{2}:\\w{2}:\\w{2}:\\w{2}").matcher(str1);
        if (localMatcher.find())
        {
          str2 = localMatcher.group();
          System.out.println("ipToHwAddr: " + paramString + " -- " + str2);
        }
      }
      str1 = localBufferedReader.readLine();
    }
    localProcess.waitFor();
    return str2;
  }

  private void a()
  {
    if (this.c)
      return;
    try
    {
      j.a(new File(R.getCacheRoot(this.b), "comm/locks/.usLock"), new a(this));
      return;
    }
    catch (Throwable localThrowable)
    {
      MobLog.getInstance().w(localThrowable);
    }
  }

  private boolean a(String paramString1, String paramString2)
  {
    HashMap localHashMap1 = new HashMap();
    localHashMap1.put("imei", DeviceHelper.getInstance(this.b).getIMEI());
    localHashMap1.put("serialno", DeviceHelper.getInstance(this.b).getSerialno());
    localHashMap1.put("mac", DeviceHelper.getInstance(this.b).getMacAddress());
    localHashMap1.put("model", DeviceHelper.getInstance(this.b).getModel());
    localHashMap1.put("plat", Integer.valueOf(1));
    HashMap localHashMap2 = new HashMap();
    localHashMap2.put("mac", paramString2);
    localHashMap2.put("udpbody", paramString1);
    localHashMap1.put("iosdata", localHashMap2);
    String str1 = Base64.encodeToString(Data.AES128Encode("sdk.commonap.sdk", new Hashon().fromHashMap(localHashMap1)), 2);
    ArrayList localArrayList = new ArrayList();
    localArrayList.add(new KVPair("m", str1));
    NetworkHelper.NetworkTimeOut localNetworkTimeOut = new NetworkHelper.NetworkTimeOut();
    localNetworkTimeOut.connectionTimeout = 5000;
    localNetworkTimeOut.readTimout = 30000;
    String str2 = new NetworkHelper().httpPost("http://devs.data.mob.com:80/macinfo", localArrayList, null, null, localNetworkTimeOut);
    return (str2 != null) && (str2.contains("\"status\":200"));
  }

  private byte[] a(byte paramByte, short paramShort, byte[] paramArrayOfByte, int paramInt, String paramString)
  {
    switch (paramByte)
    {
    case 2:
    default:
      return null;
    case 1:
      return a(paramShort);
    case 3:
    }
    return a(paramShort, paramArrayOfByte, paramInt, paramString);
  }

  private byte[] a(short paramShort)
  {
    switch (paramShort)
    {
    default:
      return null;
    case 1:
    }
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream);
    localDataOutputStream.writeShort(paramShort);
    localDataOutputStream.writeByte(2);
    localDataOutputStream.writeInt(0);
    localDataOutputStream.flush();
    localDataOutputStream.close();
    return localByteArrayOutputStream.toByteArray();
  }

  private byte[] a(short paramShort, byte[] paramArrayOfByte, int paramInt, String paramString)
  {
    switch (paramShort)
    {
    default:
    case 1:
    }
    String str1;
    String str2;
    do
    {
      return null;
      str1 = new String(paramArrayOfByte, 11, paramInt, "utf-8");
      str2 = a(paramString);
    }
    while ((str2 == null) || (!a(str1, str2)));
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    DataOutputStream localDataOutputStream = new DataOutputStream(localByteArrayOutputStream);
    localDataOutputStream.writeShort(paramShort);
    localDataOutputStream.writeByte(4);
    localDataOutputStream.writeInt(0);
    localDataOutputStream.flush();
    localDataOutputStream.close();
    return localByteArrayOutputStream.toByteArray();
  }

  private void b()
  {
    this.c = false;
  }

  private void c()
  {
    try
    {
      DatagramSocket localDatagramSocket = new DatagramSocket(9058);
      localDatagramSocket.setSoTimeout(5000);
      byte[] arrayOfByte1 = new byte[16395];
      while (true)
      {
        boolean bool = this.c;
        if (!bool)
          break;
        try
        {
          if (!com.mob.commons.a.a(this.b))
            return;
          DatagramPacket localDatagramPacket = new DatagramPacket(arrayOfByte1, arrayOfByte1.length);
          localDatagramSocket.receive(localDatagramPacket);
          InetAddress localInetAddress = localDatagramPacket.getAddress();
          int i = localDatagramPacket.getPort();
          short s = (short)(((0xFF & arrayOfByte1[0]) << 8) + (0xFF & arrayOfByte1[1]));
          byte b1 = arrayOfByte1[2];
          int j = ((0xFF & arrayOfByte1[3]) << 24) + ((0xFF & arrayOfByte1[4]) << 16) + ((0xFF & arrayOfByte1[5]) << 8) + (0xFF & arrayOfByte1[6]);
          if (j > 0)
          {
            long l = ((0xFF & arrayOfByte1[7]) << 24) + ((0xFF & arrayOfByte1[8]) << 16) + ((0xFF & arrayOfByte1[9]) << 8) + (0xFF & arrayOfByte1[10]);
            CRC32 localCRC32 = new CRC32();
            localCRC32.update(arrayOfByte1, 11, j);
            if (l != localCRC32.getValue());
          }
          else
          {
            byte[] arrayOfByte2 = a(b1, s, arrayOfByte1, j, localInetAddress.getHostAddress());
            if (arrayOfByte2 != null)
              localDatagramSocket.send(new DatagramPacket(arrayOfByte2, arrayOfByte2.length, localInetAddress, i));
          }
        }
        catch (SocketTimeoutException localSocketTimeoutException)
        {
        }
        catch (Throwable localThrowable2)
        {
          MobLog.getInstance().w(localThrowable2);
        }
      }
    }
    catch (Throwable localThrowable1)
    {
      MobLog.getInstance().w(localThrowable1);
    }
  }

  public static void start(Context paramContext)
  {
    try
    {
      if (a == null)
        a = new UDPServer(paramContext);
      a.a();
      return;
    }
    finally
    {
    }
  }

  public void stop()
  {
    try
    {
      if (a != null)
        a.b();
      return;
    }
    finally
    {
      localObject = finally;
      throw localObject;
    }
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.mob.commons.iosbridge.UDPServer
 * JD-Core Version:    0.6.2
 */